package cn.edu.nwafu.nic.nucleic_acid_test.controller;

import cn.edu.nwafu.nic.nucleic_acid_test.common.Result;
import cn.edu.nwafu.nic.nucleic_acid_test.entities.User;
import cn.edu.nwafu.nic.nucleic_acid_test.services.UserService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: SungLee
 * @date: 2022-02-19 19:21
 * @description: User相关的Controller
 */
@RestController
@RequestMapping("/api/user")
@Api(tags = "用户相关操作接口")
public class UserController {
    private static final Logger logger = LoggerFactory.getLogger(UserController.class);
    @Autowired
    private UserService userService;
    /*@ApiOperation(value = "用户列表",notes="查询所有用户")
    @RequestMapping(path = "/list", method = RequestMethod.GET)
    public Result list() {
        List<User> userList = userService.list();
        return Result.success(userList);
    }

    @ApiOperation(value = "查询用户",notes = "根据id查询用户")
    @ApiImplicitParam(paramType = "path",name="id",value = "用户id",required = true)
    @GetMapping("/query/{id}")
    public Result getUserById(@PathVariable Integer id) {
        User user = userService.getById(id);
        return Result.success(user);
    }

    @ApiOperation(value = "删除用户",notes = "根据id删除用户")
    @ApiResponses({
            @ApiResponse(code=200,message="删除成功"),
            @ApiResponse(code=500,message="删除失败")})
    @DeleteMapping("/delete/{id}")
    public Integer deleteUserById(@PathVariable Integer id) {
        return id;
    }

    @ApiOperation(value = "添加用户",notes = "添加一个用户，传入用户名和性别")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name="username",value = "用户名",required = true,defaultValue = "张三"),
            @ApiImplicitParam(paramType = "query",name="pwd",value = "密码",required = true,defaultValue = "aaa")
    })
    @PostMapping("/insert")
    public String addUser(@RequestParam String username,@RequestParam String pwd){
        return username+","+pwd;
    }

    @ApiOperation(value="修改用户",notes = "根据传入的用户信息修改用户")
    @PutMapping("/user")
    public String updateUser(@RequestBody User user){
        return user.toString();
    }*/

}
